package com.wiscamp.ninechapters.problems.infrastructure.mappers.assessments;

import com.wiscamp.ninechapters.problems.infrastructure.po.assessments.AssessmentDetailPO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

@Repository
public interface AssessmentDetailMapper extends JpaRepository<AssessmentDetailPO, Long>, JpaSpecificationExecutor<AssessmentDetailPO> {

    @Query("select e from AssessmentDetailPO e where e.assessmentId = :assessmentId and e.deleted = false and e.active = true order by e.moduleName, e.programIndex")
    Collection<AssessmentDetailPO> findAssessmentDetails(long assessmentId);

    @Query("select e from AssessmentDetailPO e where e.assessmentId = :assessmentId and e.moduleName = :moduleName and e.programName = :programName  and e.programIndex = :programIndex and e.deleted = false and e.active = true")
    AssessmentDetailPO findAssessmentDetail(long assessmentId, String moduleName, String programName, int programIndex);

    @Query("select e from AssessmentDetailPO e where e.assessmentId = :assessmentId  and e.programIndex = :programIndex and e.deleted = false and e.active = true")
    AssessmentDetailPO findAssessmentDetail(long assessmentId, int programIndex);
}